package com.itheima.springbootinit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    //@Value方式获取
    @Value("${name}")
    private String name;
    @Value("${person.name}")
    private String name2;
    @Value("${person.age}")
    private int age;
    @Value("${address[0]}")
    private String address1;
    @Value("${address[1]}")
    private String address2;
    @Value("${msg1}")
    private String msg1;
    @Value("${msg2}")
    private String msg2;

    //Environment获取配置信息
    @Autowired
    private Environment evn;
    @Autowired
    private Person person;

    /**
     * 获取配置文件中的自定义数据
     */
    @RequestMapping("hello1")
    public void test1() {
        System.out.println(name);
        System.out.println(name2);
        System.out.println(age);
        System.out.println(address1);
        System.out.println(address2);
        System.out.println(msg1);
        System.out.println(msg2);
        System.out.println("------------------------------------------------");
        System.out.println(evn.getProperty("name"));
        System.out.println(evn.getProperty("person.name"));
        System.out.println(evn.getProperty("address[0]"));
        System.out.println(person);
    }

    @RequestMapping("/hello")
    public String test() {
        return "hello springboot!!";
    }
}
